package ControllerView

import View.{KeyInfoView, ImportSoftView, ToolsWindow}
import com.trolltech.qt.gui.{QWidget, QFileDialog}
import AndroidProjectFile.MarketKey
import FilesGenerator.{UserConfig, ProjectGenerator}

/**
 * Created by IntelliJ IDEA.
 * User: danymorard
 * Date: 14.04.11
 * Time: 20:46
 * To change this template use File | Settings | File Templates.
 */

class ControllerToolsView extends ControllerView{


  var toolsWindow = new ToolsWindow (this, null)
  toolsWindow.show
  toolsWindow.android.hide

  var importSoftView = new ImportSoftView(this, toolsWindow)
  importSoftView.hide
  importSoftView.android.hide

  var keyView = new KeyInfoView (this, toolsWindow)
  keyView.show
  keyView.android.hide



  def keyActionButtonPressed() {
    // if market key setted, fill fields

    if(MarketKey.exists){
      MarketKey.load
      keyView.lineEditPath.setText(MarketKey.path)
      keyView.lineEditAlias.setText(MarketKey.alias)
      keyView.lineEditAliasPass.setText(MarketKey.aliasPass)
      keyView.lineEditStorePass.setText(MarketKey.storePass)
    }

    importSoftView.hide
    keyView.show
  }


  def softActionButtonPressed() {

    // if userconfig exist -> fill all fields
    if(UserConfig.exists){
      importSoftView.lineEditScala.setText(UserConfig.scalaPath)
      importSoftView.lineEditProguard.setText(UserConfig.proguardPath)
      importSoftView.lineEditsdk.setText(UserConfig.androidSdkPath)
    }

    importSoftView.show
    keyView.hide
  }

  def browseKeyPath() {
    keyView.lineEditPath.setText(QFileDialog.getOpenFileName(new QWidget, new String("Select your Android key"), new String(""), new QFileDialog.Filter("android Key (*.keystore)")))
  }

  def applyPressed() {


    // assign values
    MarketKey.path = keyView.lineEditPath.text
    MarketKey.alias = keyView.lineEditAlias.text
    MarketKey.aliasPass = keyView.lineEditAlias.text
    MarketKey.storePass = keyView.lineEditStorePass.text
    // save values
    MarketKey.save

    UserConfig.scalaPath = importSoftView.lineEditScala.text
    UserConfig.proguardPath = importSoftView.lineEditProguard.text
    UserConfig.androidSdkPath = importSoftView.lineEditsdk.text

    UserConfig.save

  }


  /**
   * This method is called when the view is launched
   */
 /* def viewWillAppear{


    // clear all text edit
    keyView.clearLineEdit


    // init the line path
    if(UserConfig.exists){

      importSoftView.lineEditProguard.setText(UserConfig.proguardPath)
      importSoftView.lineEditScala.setText(UserConfig.scalaPath)
      importSoftView.lineEditsdk.setText(UserConfig.androidSdkPath)

    }else{

      importSoftView.lineEditProguard.clear
      importSoftView.lineEditScala.clear
      importSoftView.lineEditsdk.clear
    }
  }*/
}